package org.jetnuke.blocks;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.velocity.VelocityContext;
import org.jetnuke.common.IAdminInfo;
import org.jetnuke.common.IBlock;
import org.jetnuke.common.IBlockInfo;
import org.jetnuke.common.IUserInfo;
import org.jetnuke.dao.DataAccessDriver;
import org.jetnuke.entities.Referer;



public class LastReferers implements IBlock {

	/* (non-Javadoc)
	 * @see org.jetnuke.common.IBlock#serviceBlock(javax.servlet.http.HttpServletRequest, org.apache.velocity.VelocityContext, org.jetnuke.common.IBlockInfo, org.jetnuke.common.IUserInfo, org.jetnuke.common.IAdminInfo)
	 */
	public void serviceBlock(HttpServletRequest req, VelocityContext vc,
			IBlockInfo blockInfo, IUserInfo userInfo, IAdminInfo adminInfo)
			throws Exception {
		int limit=10;
		List ls=
			DataAccessDriver.getInst().newRefererDAO().selectOrderRID(limit);
		for(int i=0;i<ls.size();i++){
		
			Referer ref=(Referer)ls.get(i);
			if(ref.getURL()!=null){
				ref.setURL(ref.getURL().replaceAll("&", "&amp;"));
			}
		}
		vc.put("referers",ls);
		if(adminInfo!=null && adminInfo.IsSuperUser()){
			vc.put("count",new Integer(DataAccessDriver.getInst().newRefererDAO().countAll()));//refererPeer.count(new Criteria())));
		}

	}

}
